package com.jfinalbbs.common;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.kit.HashKit;
import com.jfinal.kit.LogKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinalbbs.module.index.IndexController;
import com.jfinalbbs.module.user.User;

/**
 * Created by Tomoya.
 * Copyright (c) 2016, All Rights Reserved.
 * http://jfinalbbs.com
 */
public class AppConfig extends JFinalConfig {

    public void configConstant(Constants me) {
        //加载配置文件
        loadPropertyFile("config.properties");
        //设置开发模式
        me.setDevMode(getPropertyToBoolean("devMode", false));
        //设置freemarker模板缓存时间为0,也就是无缓存（如果设置了开发模式,缓存时间就是0,这样在修改了页面文件后,直接刷新浏览器就可以预览了）
        me.setFreeMarkerTemplateUpdateDelay(0);
    }

    public void configRoute(Routes me) {
        me.add("/", IndexController.class, "WEB-INF/page");
    }

    public void configPlugin(Plugins me) {
        //使用c3p0数据源
        C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
        me.add(c3p0Plugin);

        //初始化表映射插件,将数据源传递过去
        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        //映射表,同样可以指定id
        arp.addMapping("user", User.class);

        me.add(arp);
    }

    public void configInterceptor(Interceptors me) {

    }

    public void configHandler(Handlers me) {

    }

    public static void main(String[] args) {
        LogKit.info(HashKit.md5("123123"));
        JFinal.start("src/main/webapp", 8080, "/", 5);
    }
}
